﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms; // For Panel Sep 21,2013 20:08

namespace RobotCleaner
{
    /// <summary>
    /// =========================
    ///    Class : Map  
    ///    Date  : Sep 16th,2013 08:39
    ///    By    : EndlessRain
    /// =========================
    /// </summary>
     [Serializable] // 表示可序列化的
    public class Map 
    {
        private int WallPoint_Count = 10;    // 墙体坐标初始数量
        private bool iscircle = false;       // 是否已绕房子一圈
        private static int wallpointcount = 0;      // 所有墙体坐标节点数
        public int AllWallPointCount
        {
            get { return wallpointcount; }
            set { wallpointcount++; }
        }
        public bool IsCircle
        {
            get { return iscircle; }
            set { iscircle = value; }
        }
        /// <summary>
        /// 墙体坐标链表 存放墙体转角节点
        /// </summary>
        public List<Point> WallPoint = new List<Point>();
        /// <summary>
        /// 清洁区坐标链表 存放将要清洁的节点
        /// </summary>
        public List<Point> CleanAreaPoint = new List<Point>();

        /// <summary>
        /// 障碍物坐标链表 存放障碍物的节点
        /// </summary>
        public List<Obstacle> ObstaclePoint = new List<Obstacle>();
        /// <summary>
        /// 污浊区域坐标链表 存放污浊区域节点
        /// </summary>
        public List<DirtyArea> DirtyPoint = new List<DirtyArea>();
        
        /// <summary>
        /// 地图初始化
        /// </summary>
        public void Map_Init(Panel panel)
        {
            // For ObstaclePoint
            // Add Point
            //ObstaclePoint.Add(new Obstacle(new Point(200, 200), new Point(300, 300)));

            for (int i = 0; i < ObstaclePoint.Count;i++ )
            {
                //ObstaclePoint[i].drawRectangle(new Point(200, 200), new Point(300, 400),panel);

                ObstaclePoint[i].drawObstacle(
                    new Point(ObstaclePoint[i].O_X,ObstaclePoint[i].O_Y),
                    new Size(ObstaclePoint[i].O_width ,ObstaclePoint[i].O_height),
                    panel);

                //MessageBox.Show(ObstaclePoint[i].O_X.ToString());
                //MessageBox.Show("Added ObstaclePoint");
                //MessageBox.Show(i.ToString());
            }
            // For DirtyPoint
            // Sep 28,2013 21:08 EndlessRain
            for (int j = 0; j < DirtyPoint.Count; j++)
            {
                DirtyPoint[j].drawDirty(
                    new Point(DirtyPoint[j].D_X, DirtyPoint[j].D_Y),
                    new Size(DirtyPoint[j].D_Width, DirtyPoint[j].D_Height),
                    panel);
            }

            // 初始化墙体坐标数量
            WallPoint.Capacity = WallPoint_Count;
            // 将墙体坐标数量赋值给清洁区坐标数量
            //CleanAreaPoint.Capacity = WallPoint.Capacity;
        }
        /// <summary>
        /// 增加地图坐标
        /// </summary>
        /// <param name="_p">目标坐标</param>
        public void Map_AddWallPoint(Point _p)
        {
            WallPoint.Add(_p);
        }
        /// <summary>
        /// 增加可清理区域坐标
        /// </summary>
        /// <param name="_p">目标坐标</param>
        public void Map_AddCleanAreaPoint(Point _p)
        {
            CleanAreaPoint.Add(_p);
        }
        /// <summary>
        /// 地图坐标清理工作
        /// </summary>
        public void Map_Clear()
        {
            WallPoint.Clear();
            CleanAreaPoint.Clear();
        }
        /// <summary>
        /// 加载已存地图数据 （扩展功能，暂不实现）
        /// </summary>
        public void Map_Load()
        { 
            // Load Map File here
        }
    }
}
